<!---------------------------------------------------------------------------->
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> Microsoft WAVE soundfile format </title>
<meta name="Document-Owner" content="Craig Sapp (craig@ccrma.stanford.edu)"> 
<meta name="Author" content="Craig Stuart Sapp (craig@ccrma.stanford.edu)">
<meta name="Creation-Date" content=" Thu Dec 11 08:28:30 GMT-0800 1997 ">
<meta name="Revision-Date" content=" Thu Dec 11 08:28:37 GMT-0800 1997 ">
</head>
<!---------------------------------------------------------------------------->
<body bgcolor="#b7cbed">    

<h1> WAVE PCM soundfile format <hr noshade="noshade"> </h1>



<p> The WAVE file format is a subset of Microsoft's RIFF specification
for the storage of multimedia files. A RIFF file starts out with
a file header followed by a sequence of data chunks. A WAVE file
is often just a RIFF file with a single "WAVE" chunk which consists
of two sub-chunks -- a "fmt " chunk specifying the data format and
a "data" chunk containing the actual sample data. Call this form
the "Canonical form".  Who knows how it really all works. 

</p><p>
I use the standard WAVE format as created by the 
<a target="_top" href="http://www.spies.com/Sox/">sox</a> program:

</p><p>
</p><center> <img src="Microsoft_WAVE_soundfile_format_files/wav-sound-format.gif"> </center>




<pre>Offset  Size  Name             Description
<hr noshade="noshade">
The canonical WAVE format starts with the RIFF header:

0         4   <b>ChunkID</b>          Contains the letters "RIFF" in ASCII form
                               (0x52494646 big-endian form).
4         4   <b>ChunkSize</b>        36 + SubChunk2Size, or more precisely:
                               4 + (8 + SubChunk1Size) + (8 + SubChunk2Size)
                               This is the size of the rest of the chunk 
                               following this number.  This is the size of the 
                               entire file in bytes minus 8 bytes for the
                               two fields not included in this count:
                               ChunkID and ChunkSize.
8         4   <b>Format</b>           Contains the letters "WAVE"
                               (0x57415645 big-endian form).

The "WAVE" format consists of two subchunks: "fmt " and "data":
The "fmt " subchunk describes the sound data's format:

12        4   <b>Subchunk1ID</b>      Contains the letters "fmt "
                               (0x666d7420 big-endian form).
16        4   <b>Subchunk1Size</b>    16 for PCM.  This is the size of the
                               rest of the Subchunk which follows this number.
20        2   <b>AudioFormat</b>      PCM = 1 (i.e. Linear quantization)
                               Values other than 1 indicate some 
                               form of compression.
22        2   <b>NumChannels</b>      Mono = 1, Stereo = 2, etc.
24        4   <b>SampleRate</b>       8000, 44100, etc.
28        4   <b>ByteRate</b>         == SampleRate * NumChannels * BitsPerSample/8
32        2   <b>BlockAlign</b>       == NumChannels * BitsPerSample/8
                               The number of bytes for one sample including
                               all channels. I wonder what happens when
                               this number isn't an integer?
34        2   <b>BitsPerSample</b>    8 bits = 8, 16 bits = 16, etc.
<font color="888888">          2   <b>ExtraParamSize</b>   if PCM, then doesn't exist
          X   <b>ExtraParams</b>      space for extra parameters</font>

The "data" subchunk contains the size of the data and the actual sound:

36        4   <b>Subchunk2ID</b>      Contains the letters "data"
                               (0x64617461 big-endian form).
40        4   <b>Subchunk2Size</b>    == NumSamples * NumChannels * BitsPerSample/8
                               This is the number of bytes in the data.
                               You can also think of this as the size
                               of the read of the subchunk following this 
                               number.
44        *   <b>Data</b>             The actual sound data.
<hr noshade="noshade">
</pre>

<pre>
</pre>

<a name="example"> </a>
<p> As an example, here are the opening 72 bytes of a WAVE file with
bytes shown as hexadecimal numbers:

</p><pre><b>52 49 46 46 24 08 00 00 57 41 56 45 66 6d 74 20 10 00 00 00 01 00 02 00 </b>
<b>22 56 00 00 88 58 01 00 04 00 10 00 64 61 74 61 00 08 00 00 00 00 00 00 </b>
<b>24 17 1e f3 3c 13 3c 14 16 f9 18 f9 34 e7 23 a6 3c f2 24 f2 11 ce 1a 0d </b>
</pre>

<p> Here is the interpretation of these bytes as a WAVE soundfile:

<img src="Microsoft_WAVE_soundfile_format_files/wave-bytes.gif">


</p><hr noshade="noshade">


<h3> Notes: </h3>

<ul>

<li> The default byte ordering assumed for WAVE data files is little-endian.
 Files written using the big-endian byte ordering scheme have the identifier 
 RIFX instead of RIFF.
</li><li> The sample data must end on an even byte boundary. Whatever that means.

</li><li> 8-bit samples are stored as unsigned bytes, ranging from 0 to 255. 
     16-bit samples are stored as 2's-complement signed integers, 
     ranging from -32768 to 32767.

</li><li> There may be additional subchunks in a Wave data stream. If so,
each will have a char[4] SubChunkID, and unsigned long SubChunkSize,
and SubChunkSize amount of data.

</li><li> RIFF stands for <i>Resource Interchange File Format</i>.

</li></ul>


<h3> General discussion of RIFF files: </h3>

Multimedia applications require the storage and management of a
wide variety of data, including bitmaps, audio data, video data,
and peripheral device control information. RIFF provides a 
way to store all these varied types of data. The type of data a
RIFF file contains is indicated by the file extension. Examples of
data that may be stored in RIFF files are:

<ul>
<li> Audio/visual interleaved data (.AVI)
</li><li> Waveform data (.WAV)
</li><li> Bitmapped data (.RDI)
</li><li> MIDI information (.RMI)
</li><li> Color palette (.PAL)
</li><li> Multimedia movie (.RMN)
</li><li> Animated cursor (.ANI)
</li><li> A bundle of other RIFF files (.BND)
</li></ul>

NOTE:

At this point, AVI files are the only type of RIFF files that have
been fully implemented using the current RIFF specification. Although
WAV files have been implemented, these files are very simple, and
their developers typically use an older specification in constructing
them.

<p>
For more info see 
<a target="_top" href="http://www.ora.com/centers/gff/formats/micriff/index.htm">
http://www.ora.com/centers/gff/formats/micriff/index.htm</a>




</p><pre>
</pre>

<h3> References: </h3>

<ol>

<li> <a target="_top" href="http://netghost.narod.ru/gff/graphics/summary/micriff.htm">
http://netghost.narod.ru/gff/graphics/summary/micriff.htm</a> RIFF Format Reference (good).

</li><li> <a target="_top" href="http://www.lightlink.com/tjweber/StripWav/WAVE.html">
http://www.lightlink.com/tjweber/StripWav/WAVE.html </a>

</li></ol>


<pre>







</pre>


<hr noshade="noshade">

<address> craig@ccrma.stanford.edu </address> (Updated by Scott Wilson Jan 20, 2003)


</body></html>